# -*- coding: utf-8 -*-
# @Time    : 2020/6/15 2:47
# @Author  : dearMrYang
# @File    : form.py
# @Software: PyCharm
from django import forms


class FormMixin(forms.Form):

    def get_error(self):
        if hasattr(self, 'errors'):
            errors = self.errors.get_json_data()
            print(errors)
            new_errors = {}
            for key, message_dicts in errors.items():
                messages = []
                for message in message_dicts:
                    messages.append(message['message'])
                new_errors[key] = messages
            return new_errors
        else:
            return {}
